package exercises.Charpter10;

interface Selector {
	boolean end();
	Object current();
	void next();
}

class MyString{
	private String str = "";

	public MyString(String str) {
		this.str = str;
	}

	public String toString() {
		return str;
	}
}

public class Two {
	private Object[] items;
	private int next = 0;
	
	Two(int size){
		items = new Object[size]; 
	}
	
	public void add(Object x){
		if (next < items.length){
			items[next++] = x;
		}
	}
	
	private class myStringSelector implements Selector{
		private int i = 0;
		public boolean end() {
			return i == items.length;
		}

		public Object current() {
			return items[i];
		}

		public void next() {
			if(i < items.length){i++;}
			
		}
		
	}
	
	public Selector selector(){
		return new myStringSelector();
	}
	
	public static void main(String[] args){
		Two sequence = new Two(10);
		for (int i = 0; i < 10; i++){
			sequence.add(new MyString("test" + i));
		}
		
		Selector selector = sequence.selector();
		while (!selector.end()) {
			System.out.println(selector.current().toString() + " ");
			selector.next();
		}
	}
}
